/**
 * 自定义指令  防抖指令
 * vueuse
 * 使用Demo：
 * <template>
 *    <a href="#" v-copy="'test'">删除</a>
 * </template>
 */
// import { useDebounceFn } from "@vueuse/core";
import type { ObjectDirective, DirectiveBinding } from "vue";

interface IMyInterface extends HTMLElement {
	debounced: any;
	disabled: boolean;
}
const vDisabled: ObjectDirective = {
	mounted(el: IMyInterface, binding: DirectiveBinding) {
		const { value } = binding;
		// 实现按钮禁用
		el.disabled = true;

		// 增加 elementUI 的禁用样式类
		el.classList.add("is-disabled");

		// 解除 disabled
		// 可以通过 v-disabled=2000，指定禁用2000毫秒，默认禁用1000毫秒
		setTimeout(() => {
			el.classList.remove("is-disabled");
			el.disabled = false;
		}, value ?? 1000); // 设置禁用时长
		/* 	el.addEventListener("click", (e: Event) => {
			// 阻止默认事件
			e.preventDefault();
			// 阻止冒泡
			e.stopPropagation();
			el.disabled = true;
			console.log(el, value);
		}); */
	},
};

export default {
	name: "disabled",
	...vDisabled,
};
